home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mcomm / comm.h < prev    next >
C/C++ Source or Header  |  1994-10-02  |  13KB  |  245 lines

  1.  
  2. /****************************************************************************
  3.  COMM.H -- header file for C programs using MCOMM5 Async Lib
  4.    Mike Dumdei,  6 Holly Lane,  Texarkana TX  75503    (c) 1989-94
  5.  New COMM structure implemented in 5.42 <<< ALWAYS USE CURRENT COMM.H >>>
  6. ****************************************************************************/
  7.  
  8. #ifndef MCOMM
  9.   #define _C_ cdecl
  10.   #define _V_ volatile
  11.   #define _F_ far
  12.   #if (__TURBOC__ && __HUGE__)
  13.     #define _N_
  14.   #else
  15.     #define _N_ near
  16.   #endif
  17.   #define MCOMM
  18. #endif
  19.  
  20. /*  ---- Return codes ----  */
  21. #ifndef __ZTC__
  22.   #define       R_OK           0x0000
  23. #endif
  24. #define         R_NOMEM        0x0001
  25. #define         R_BAUDERR      0x0002
  26. #define         R_PARITYERR    0x0004
  27. #define         R_DTABITERR    0x0008
  28. #define         R_STPBITERR    0x0010
  29. #define         R_IRQUSED      0x0020
  30. #define         R_VCTRUSED     0x0040
  31. #define         R_NOPORT       0x0080
  32. #define         R_PORTUSED     0x0100
  33. #define         R_UARTERR      0x0200
  34.  
  35. #define         R_TXERR        0xffff
  36.  
  37. /* ---- Interrupt bit masks ---- */
  38. #define         IRQMASK(irqnum)  (1 << ((irqnum) & 7))
  39. #define         IRQ2         0x04
  40. #define         IRQ3         0x08
  41. #define         IRQ4         0x10
  42. #define         IRQ5         0x20
  43. #define         IRQ6         0x40
  44. #define         IRQ7         0x80
  45. #define         IRQ10        0x04
  46. #define         IRQ11        0x08
  47. #define         IRQ12        0x10
  48. #define         IRQ14        0x40
  49. #define         IRQ15        0x80
  50.  
  51. /* ---- Vector numbers ---- */
  52. #define         VCTR(irqnum)     (((irqnum) < 8) ? (irqnum)+8 : (irqnum)+104)
  53. #define         VCTR2          10
  54. #define         VCTR3          11
  55. #define         VCTR4          12
  56. #define         VCTR5          13
  57. #define         VCTR6          14
  58. #define         VCTR7          15
  59. #define         VCTR10         114
  60. #define         VCTR11         115
  61. #define         VCTR12         116
  62. #define         VCTR14         118
  63. #define         VCTR15         119
  64.  
  65. /* ---- Standard Comm Ports ---- */
  66. #define         COM1        0x3f8, 0x10, 12
  67. #define         COM2        0x2f8, 0x08, 11
  68. #define         COM3        0x3e8, 0x10, 12
  69. #define         COM4        0x2e8, 0x08, 11
  70.  
  71. /* ---- Defines for Async_regs() ---- */
  72. #define         RXreg       0
  73. #define         TXreg       0
  74. #define         IERreg      1
  75. #define         IIDreg      2
  76. #define         FCRreg      2
  77. #define         LCRreg      3
  78. #define         MCRreg      4
  79. #define         LSRreg      5
  80. #define         MSRreg      6
  81. #define         LObaud      0
  82. #define         HIbaud      1
  83. #define         RDreg      (-1)
  84.  
  85. /* ---- Miscellaneous bits ---- */
  86. #define         B_DTR        0x0001
  87. #define         B_RTS        0x0002
  88.  
  89. /*  ---- Status bit masks ----  */
  90.                         /*    S T A T 2    */
  91. #define         B_XUSE       0x0001         /* using XON/XOFF protocol bit */
  92. #define         B_XRXD       0x0002                   /* XOFF received bit */
  93. #define         B_XSENT      0x0004                       /* XOFF sent bit */
  94. #define         B_TXEMPTY    0x0008             /* nothing to transmit bit */
  95. #define         B_CTS        0x0010                   /* clear to send bit */
  96. #define         B_DSR        0x0020                  /* data set ready bit */
  97. #define         B_FLOWHALT   0x0040             /* flow halt indicator bit */
  98. #define         B_MNTR_CD    0x0080                      /* monitor CD bit */
  99.  
  100.                         /*    S T A T 1    */
  101. #define         B_RXOVF      0x0100        /* rx buffer overflow indic bit */
  102. #define         B_OVERRUN    0x0200              /* char overrun error bit */
  103. #define         B_PARITY     0x0400                    /* parity error bit */
  104. #define         B_FRAMING    0x0800                   /* framing error bit */
  105. #define         B_BREAK      0x1000          /* line break signal detected */
  106. #define         B_THRE       0x2000      /* used by int handler (always 0) */
  107. #define         B_RXEMPTY    0x4000                 /* rx buffer empty bit */
  108. #define         B_CD         0x8000             /* carrier detect bit mask */
  109.  
  110.                         /*    S T A T 3    */
  111. #define         B_IGNERR     0x0001  /* discard chars with par, frm'g errs */
  112. #define         B_16550      0x0002                      /* 16550 detected */
  113. #define         B_FIFO       0x0004                 /* 16550 FIFOs enabled */
  114. #define         B_ORGFIFO    0x0008  /* FIFOs were on when port was opened */
  115. #define         B_XUSET      0x0020     /* using XON/XOFF on txmt side bit */
  116. #define         B_XUSER      0x0040     /* using XON/XOFF on recv side bit */
  117. #define         B_XONANY     0x0080          /* accept any char for an XON */
  118.  
  119.  
  120. /*  ----  P O R T   S T R U C T U R E   ---- */
  121.  
  122. #pragma pack(1)      /* be sure and use byte align to reference port struc */
  123.  
  124. typedef struct
  125. {
  126.     int ComBase;                     /* base port address of for comm port */
  127.     char IRQMask;                        /* mask for IRQ used by this port */
  128.     char Vector;                     /* interrupt vector used by this port */
  129.     char BPDSstr[10];               /* current baud,parity,data,stop parms */
  130.     int RxSize;                                    /* size of receive bufr */
  131.     int TxSize;                                   /* size of transmit bufr */
  132.     int RingSeg;              /* segment of rx/tx bufrs (leave 0 for NEAR) */
  133.     int RingOfst;                    /* offset of rx/tx bufrs, alias TxTop */
  134.     int RxTop;                     /* ptr to begin of rx bufr, alias TxBtm */
  135.     int RxBtm;                          /* ptr to end of rx bufr (end + 1) */
  136.     int _V_ TxIn;                          /* ptr to where next 'put' goes */
  137.     int _V_ TxOut;                    /* ptr to where next tx'd comes from */
  138.     int _V_ TxFree;                             /* remaining tx bufr space */
  139.     int _V_ RxIn;                       /* pointer to where next rx'd goes */
  140.     int _V_ RxOut;                   /* ptr to where next 'get' comes from */
  141.     int _V_ RxFree;                    /* remaining bytes in rx bufr space */
  142.     int BaudDvsr;                                     /* baud rate divisor */
  143.     int XoffTrip;          /* send XOFF when this many bytes left in rxbuf */
  144.     int XonTrip;            /* send XON when this many bytes left in rxbuf */
  145.     int OldVctrOfst;          /* OFST address of original interrupt vector */
  146.     int OldVctrSeg;            /* SEG address of original interrupt vector */
  147.     int OldDvsr;                    /* original value of Baud Divisor Regs */
  148.     char _V_ Stat2;                               /* secondary status byte */
  149.     char _V_ Stat1;                                 /* primary status byte */
  150.     char _V_ TxStat;          /* determines when tx_intrpts need turned on */
  151.     char MSRMask;               /* slcts bits in MSR montrd for flow cntrl */
  152.     char _V_ MSRVal;             /* present value of modem status register */
  153.     char _V_ Stat3;                  /* another flag, used for XONANY char */
  154.     char PDSinfo;                       /* parity, # dta bits, # stop bits */
  155.     char StripMask;                         /* mask for high bit stripping */
  156.     char XTxRptInit;              /* initialization value for XTxRpt below */
  157.     char _V_ XTxRpt;               /* countdown val befr repeat tx of XOFF */
  158.     char _V_ TxImmedChar;               /* char to be tx'd 1st opportunity */
  159.     char HdlrUsed;             /* assigned interrupt handler for this port */
  160.     char Old8259Msk;                       /* original 8259 interrupt mask */
  161.     char OldLCR;                        /* original Line Control Reg value */
  162.     char OldMCR;                         /* original Modem Cntrl Reg value */
  163.     char OldIER;                    /* original Interrupt Enable Reg value */
  164.     int TxByteCnt;                /* number bytes to send per tx interrupt */
  165.     char FCRVal;                        /* FIFO control register data byte */
  166.     char IERVal;                        /* interrupt en